package cn.hdu.liang.ch2;

public class ThreadStopping2 {
    public static void main(String[] args) {
        class StoppableThread extends Thread {
            private boolean stoped;

            @Override
            public void run() {
                synchronized(this) {
                    while(!stoped) {
                        System.out.println("running");
                    }
                }
            }

            synchronized void stopThread() {
                stoped = true;
            }
        }

        StoppableThread thd = new StoppableThread();
        thd.start();

        try {
            Thread.sleep(1000);
        } catch(InterruptedException ie) {

        }

        thd.stopThread();
    }
}
